﻿Imports System
Imports System.IO
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Common
Imports System.Reflection

Public Class frmMenu

    Sub initScreen()
        manipulateMenuAccessRight()

        If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
            notifyRejectedWeld()
        ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then

        End If
    End Sub

    Private Sub MenuItemCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        dispatchCouponScreen()
    End Sub

    Private Sub btnMenuCoupon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMenuCoupon.Click
        dispatchCouponScreen()
    End Sub

    Private Sub btnWeldingSequence_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWeldingSequence.Click
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_WELDING_SEQ

        frmWeldingSeq.Show()
        frmWeldingSeq.initScreen()
        Me.Hide()
    End Sub

    Private Sub btnReplaceRejectedWeld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceRejectedWeld.Click
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_REPLACE_WELD

        frmReplaceWeld.Show()
        frmReplaceWeld.initScreen()
        Me.Hide()
    End Sub

    Private Sub btnAcceptReject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAcceptReject.Click
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_WELD_AR

        frmWeldAR.Show()
        frmWeldAR.initScreen()
        Me.Hide()
    End Sub

    Private Sub MenuItemAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_WELD_AR

        frmWeldAR.Show()
        frmWeldAR.initScreen()
        Me.Hide()
    End Sub

    Private Sub MenuItemReplaceWeld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_REPLACE_WELD

        frmReplaceWeld.Show()
        frmReplaceWeld.initScreen()
        Me.Hide()
    End Sub

    Private Sub MenuItemWeldSeq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_REPLACE_WELD

        frmWeldingSeq.Show()
        frmWeldingSeq.initScreen()
        Me.Hide()
    End Sub

    Private Sub MenuItemLogOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemLogOut.Click    
        _FROM_SCREEN_ID = _SCREEN_ID
        _SCREEN_ID = SCREEN_PROJECT

        frmProject.Show()
        frmProject.initScreen()
        Me.Hide()
    End Sub

    Sub dispatchCouponScreen()
        If (Globals.USER_ROLE_WELDER = _USER_ROLE) Then
            _FROM_SCREEN_ID = _SCREEN_ID
            _SCREEN_ID = SCREEN_COUPON_LIST

            frmCouponList.Show()
            frmCouponList.initScreen()
        ElseIf (Globals.USER_ROLE_ENGINEER = _USER_ROLE) Then
            _FROM_SCREEN_ID = _SCREEN_ID
            _SCREEN_ID = SCREEN_ENGINEER_COUPON

            frmEngineerCoupon.Show()

            frmEngineerCoupon.cboEngineerCouponStatus.Text = "Pending"
            frmEngineerCoupon.initScreen()
        End If
        Me.Hide()
    End Sub

    Sub notifyRejectedWeld()
        Dim dtResult As New DataTable
        dtResult = findWeldLogs(Nothing, Nothing, Nothing, WELDLOG_STATUS_REJECTED, Nothing, Globals.COUPON_TYPE_IN, True, Nothing, _PROJECT_ID)

        Dim rejectedWeldCount As Integer = 0
        If dtResult.Rows.Count > 0 Then
            For Each dataRow As DataRow In dtResult.Rows
                rejectedWeldCount = rejectedWeldCount + 1
            Next

            MsgBox(rejectedWeldCount & " welds pending to replace.", MsgBoxStyle.Information, "E-QAM")
        End If
    End Sub

    Sub manipulateMenuAccessRight()
        If (_USER_ROLE = Globals.USER_ROLE_ENGINEER) Then
            'Me.MenuItemAR.Enabled = True
            Me.btnAcceptReject.Enabled = True
            Me.btnAcceptReject.Visible = True
        ElseIf (_USER_ROLE = Globals.USER_ROLE_WELDER) Then
            'Me.MenuItemAR.Enabled = False
            Me.btnAcceptReject.Enabled = False
            Me.btnAcceptReject.Visible = False
        End If
    End Sub
End Class